using System;
using System.Collections.Generic;
using System.Text;

namespace Tools {
    public enum MoveOffset { FromZero, FromCurrent, FromOtherLimit }
    public class Range {


        private long begin;
        private long end;

        public Range ( ) {
            this.From = 0;
            this.Length = 0;
        }

        public Range ( Range r ) {
            this.From = r.From;
            this.To = r.To;
        }

        public Range ( long from, long length ) {
            this.From = from;
            this.Length = length;
        }

        public long Length {
            get {
                return this.To - this.From;
            }
            set {
                //Console.WriteLine( "set Length {0} -- {1}", this, value );
                this.To = this.From + value;
            }
        }

        public long From {
            set {
                this.begin = value;
            }
            get {
                return this.begin;
            }
        }
        public long To {
            set {
                this.end = value;
            }
            get {
                return this.end;
            }
        }

        //publ
        public long moveBegining ( long value, MoveOffset offset ) {
            switch ( offset ) {
                case MoveOffset.FromCurrent:
                    this.From += value;
                    break;
                case MoveOffset.FromOtherLimit:
                    this.From = this.To - value;
                    break;
                case MoveOffset.FromZero:
                    this.From = value;
                    break;
                default:
                    break;

            }
            return this.From;
        }

        public long moveEnd ( long value, MoveOffset offset ) {
            switch ( offset ) {
                case MoveOffset.FromCurrent:
                    this.To += value;
                    break;
                case MoveOffset.FromOtherLimit:
                    this.To = this.From + value;
                    break;
                case MoveOffset.FromZero:
                    this.To = value;
                    break;
                default:
                    break;

            }
            return this.To;
        }

        public override string ToString ( ) {
            return String.Format( "{0}:{1}[{2}]", this.From, this.To, this.Length );

        }

        public static implicit operator string ( Range r ) {
            return r.ToString( );
        }
    }
}
